package com.sleepcamel.resteasyConfigurator.view.updateValueStrategies;

import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.conversion.IConverter;

import com.sleepcamel.rest.domain.JavaClass;
import com.sleepcamel.resteasyConfigurator.util.ClassProvider;

public class StringToClassUpdateValueStrategy extends UpdateValueStrategy {

	public StringToClassUpdateValueStrategy() {
		setConverter(new StringToClassConverter());
	}
}

class StringToClassConverter implements IConverter{

	@Override
	public Object getFromType() {
		return String.class;
	}

	@Override
	public Object getToType() {
		return JavaClass.class;
	}

	@Override
	public Object convert(Object paramObject) {
		JavaClass clazz = null;
		if ( paramObject instanceof String ){
			clazz = ClassProvider.getInstance().getClassFor((String) paramObject);
		}
		return clazz;
	}
	
}
